package com.xuda.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @author ：程序员徐大大
 * @description：TODO
 * @date ：2022-07-29 17:46
 */
@Configuration
public class CoresConfigur {
    @Bean
    public CorsWebFilter corsWebFilter() {
        UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
        CorsConfiguration coresConfiguration = new CorsConfiguration();
        //配置跨域
        coresConfiguration.addAllowedHeader("*");
        coresConfiguration.addAllowedMethod("*");
        // coresConfiguration.addAllowedOrigin("*");
        //allowedOriginPatterns
        coresConfiguration.addAllowedOriginPattern("*");
        coresConfiguration.setAllowCredentials(true);
        urlBasedCorsConfigurationSource.registerCorsConfiguration("/**",coresConfiguration);
        return new CorsWebFilter(urlBasedCorsConfigurationSource);
    }
}
